<?php

use think\facade\Route;

Route::rest([
    'index'   => ['GET', '', 'list'],
    'read' => ['GET', '/:id', 'detail'],
    'save' => ['POST', '', 'add'],
    'update' => ['PUT', '/:id', 'edit'],
    'delete' => ['DELETE', '/:id', 'delete'],
]);


/**
 * 不需要登录路由组
 */
Route::group(function () {
    Route::get('index/init', 'Index/init')->name('admin.index.init');
    // Route::get('index/check', 'Index/check')->name('admin.index.check');
    Route::post('index/login', 'Index/login')->name('admin.index.login');
    Route::any('index/scanLogin', 'Index/scanLogin')->name('admin.index.scanLogin');
    Route::get('index/thirdLogin', 'Index/thirdLogin')->name('admin.index.thirdLogin');
    Route::get('index/loginConfig', 'Index/loginConfig')->name('admin.index.loginConfig');
    Route::get('index/captcha', 'Index/captcha')->name('admin.index.captcha');
    Route::any('test/test', 'Test/test');       // 测试路由
    Route::any('test/initData', 'Test/initData');       // 初始化安装数据
    Route::any('test/testData', 'Test/testData');       // 初始化测试数据
    Route::any('test/miniTemplate', 'Test/miniTemplate');       // 获取新的小程序订阅消息 tid,kid
    Route::any('test/websocket', 'Test/websocket');       // 测试后台 websocket 消息通知 
});


/**
 * 必须登录路由组
 */
Route::group(function () {
    // 注销登录
    Route::any('index/logout', 'Index/logout')->name('admin.index.logout');
    Route::get('index/rules', 'Index/rules')->name('admin.index.rules');
    
    Route::get('index/adminLog', 'Index/adminLog')->name('admin.index.adminLog');
    Route::post('index/clearCache', 'Index/clearCache')->name('admin.index.clearCache');

    // 消息通知类型，和未读消息数量
    Route::get('notification/notificationType', 'notification.notification/notificationType')->name('admin.notification.notification.notificationType');

    // 个人资料查看
    Route::get('index/profile', 'Index/profile')->name('admin.index.profile');

    Route::group(function () {
        // 更新管理员个人资料
        Route::put('index/update', 'Index/update')->name('admin.index.update');

        // 消息通知配置
        Route::get('notification/config/getTemplateId/:event/:channel', 'notification.Config/getTemplateId')->name('admin.notification.config.getTemplateId');
        Route::put('notification/config/setStatus/:event/:channel', 'notification.Config/setStatus')->name('admin.notification.config.setStatus');
        Route::get('notification/config/:receiver_type', 'notification.Config/list')->name('admin.notification.config.list');
        Route::get('notification/config/:event/:channel', 'notification.Config/detail')->name('admin.notification.config.detail');
        Route::put('notification/config/:event/:channel', 'notification.Config/edit')->name('admin.notification.config.edit');
    })->middleware('check_rule', 'admin');
})->middleware('check_login', 'admin');
